package dame2;

public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        
        public ListNode(int val) {
            this.val = val;
        }
    }
    ListNode head  = null;
    ListNode last = null;
    public int usesize = 0;
    public void offer(int val){  //尾插法
        ListNode node = new ListNode(val);
        if (isEmpty()){
            head = last = null;
        }
            last.next  =node;
            node.prev = last;
            last = last.next;
            head.prev = null;

            usesize++;
    }

    public int poll(){  //删除头节点
        if (isEmpty()){
           return -1;
        }
        int val = head.val;
        if (head !=null) {
            head = head.next;
        }
        usesize--;
        return val;
    }
    public int peek(){   //获取队列头元素
        return head.val;
    }
    public boolean isEmpty(){  //判断队列是否为空
        return usesize==0;
    }
}
